layui.use(['element', 'layer', 'util','jquery'],function () {
    let element = layui.element;
    let layer = layui.layer;
    let util = layui.util;
    let $ = layui.$;
    let a = $("input[name=user]").val();
    let c = a.substring(a.indexOf('(')+1,a.indexOf(')')).split(', ');
    localStorage.setItem('tabId',3);
    let d = {
        data:{}
    };
    let deleteIndex;
    for (var i = 0; i < c.length; i++) {
        var n = c[i].split('=');
        d.data[n[0]] = n[1];
    }
    localStorage.setItem("user",JSON.stringify(d));

    //获取所有导航栏
    getNav();
    //当前用户名字赋值
    $('#userName').text(d.data.account);
    //当前用户头像
    $('#headPortrait').attr('src',d.data.acatarUrl)
    //本次登录赋值
    $('#currentLoginTime').text('本次登录：' + setTime());
    //登录地区赋值
    $('#loginRegion').text('登录地区：' + returnCitySN.cname);
    //所在部门赋值
    $.ajax({
        url: '/userDept/getDeptsByUserId',
        data: {userId: d.data.userId},
        dataType: 'json',
        success: function (data) {
            var depts = data.data;
            var deptName = '';
            for (var i = 0; i < depts.length; i++) {
                if(i == depts.length - 1){
                    deptName += depts[i].deptName;
                }else{
                    deptName += depts[i].deptName + '、';
                }
            }
            $('#deptName').text('所在部门：' + deptName)
            //快捷入口
            deptMessageAlert(depts);
        }
    });
    //上次登录赋值
    $.ajax({
        url: '/JsLoginRecord/getLastLoginTimeByUserId',
        data: {userId: d.data.userId},
        dataType: 'json',
        success: function (data) {
            $('#lastTime').text('上次登录：' + data.data)
        }
    })
    //当前用户鼠标悬停
    $('.head-portrait').mouseover(function () {
        $('#personalInformation').show();
    //当前用户鼠标离开
    }).mouseout(function () {
        $('#personalInformation').hide();
    });
    //消息提示鼠标悬停
    $('#messageAlert').mouseover(function () {
        $('#deptMessageAlert').show();
    //消息提示鼠标离开
    }).mouseout(function () {
        $('#deptMessageAlert').hide();
    });
    //快捷入口鼠标悬停
    $('#oftenMenu').mouseover(function () {
        $('#inCommonUseMenu').show();
        //消息提示鼠标离开
    }).mouseout(function () {
        $('#inCommonUseMenu').hide();
    });
    //退出账户
    $('#quit').on('click',function () {
        localStorage.removeItem("user");
        $.ajax({
            url: '/login/logout',
            type: 'post',
            success: function () {
                window.location.href = '/login/login.html'
            }
        });
    });
    //快捷入口
    function deptMessageAlert(depts) {
        if(depts.length == 1){
            if(depts[0].id == 1){
                $('.menu').append(
                    '<a href="javascript:;" nav-id="9" nav-title="商品列表" class="subMenu" _href="/product/productManage/productList/product-list.html">商品列表</a>' +
                    '<a href="javascript:;" nav-id="74" nav-title="用户列表" class="subMenu" _href="/user/userManage/userList/user-list.html">用户列表</a>' +
                    '<a href="javascript:;" nav-id="56" nav-title="轮播图列表" class="subMenu" _href="/banner/bannerManage/bannerList/banner-list.html">轮播图列表</a>' +
                    '<a href="javascript:;" nav-id="14" nav-title="课程列表" class="subMenu" _href="/course/courseManage/courseList/course-list.html">课程列表</a>' +
                    '<a href="javascript:;" nav-id="86" nav-title="后台人员列表" class="subMenu" _href="/power/backStage/backStageList/back-stage-list.html">后台人员列表</a>' +
                    '<a href="javascript:;" nav-id="113" style="margin-left: 14px;" nav-title="交易统计图" class="subMenu" _href="">交易统计图</a>' +
                    '<a href="javascript:;" nav-id="23" nav-title="微圈列表" class="subMenu" _href="/microcircle/list/microcircle-list.html">微圈列表</a>' +
                    '<a href="javascript:;" nav-id="91" nav-title="部门管理" class="subMenu" _href="/power/dept/deptList/dept-list.html">部门管理</a>' +
                    '<a href="javascript:;" nav-id="51" nav-title="优惠卷列表" class="subMenu" _href="/coupon/couponManage/couponList/coupon-list.html">优惠卷列表</a>'
                );
                $('#messageAlert').show();
                $('#messageAlertCount').text(getToAuditCount(2,2) + getToAuditCount(3,2) + getToAuditCount(4,2) + getApplyForApplyRecordCount() + getDueSoonBannersCount());
            }else if(depts[0].id == 2){
                $('.menu').append(
                    '<a href="javascript:;" nav-id="16" nav-title="课程列表" class="subMenu" _href="/course/courseManage/courseList/course-list.html" >课程列表</a>' +
                    '<a href="javascript:;" nav-id="36" nav-title="课程审核列表" class="subMenu" _href="/examine/course/course-examine.html" >课程审核</a>' +
                    '<a href="javascript:;" nav-id="23" nav-title="微圈列表" class="subMenu" _href="/microcircle/list/microcircle-list.html" >微圈列表</a>' +
                    '<a href="javascript:;" nav-id="38" nav-title="微圈审核列表" class="subMenu" _href="/examine/microCircle/microCircle-examine.html" >微圈审核</a>' +
                    '<a href="javascript:;" nav-id="30" nav-title="课程评论" class="subMenu" _href="/comment/courseComment/course-comment-list.html" >课程评论</a>' +
                    '<a href="javascript:;" nav-id="31" nav-title="微圈评论" class="subMenu" _href="/comment/courseComment/course-comment-list.html" >微圈评论</a>'
                );
                //$('#messageAlertCount').text(getToAuditCount(2,1) + getReturnApplicationOrderCount(2,2) + getReturnApplicationOrderCount(3,2),getReturnApplicationOrderCount());
            }else if(depts[0].id == 3){
                $('.menu').append(
                    '<a href="javascript:;" nav-id="9" nav-title="商品列表" class="subMenu" _href="/product/productManage/productList/product-list.html" >商品列表</a>' +
                    '<a href="javascript:;" nav-id="16" nav-title="课程列表" class="subMenu" _href="/course/courseManage/courseList/course-list.html" >课程列表</a>' +
                    '<a href="javascript:;" nav-id="34" nav-title="商品审核列表" class="subMenu" _href="/examine/product/product-examine.html" >商品审核</a>' +
                    '<a href="javascript:;" nav-id="36" nav-title="课程审核列表" class="subMenu" _href="/examine/course/course-examine.html" >课程审核</a>' +
                    '<a href="javascript:;" nav-id="43" nav-title="课程订单列表" class="subMenu" _href="/Order/courseOrder/courseOrderList.html" >课程订单</a>' +
                    '<a href="javascript:;" nav-id="45" nav-title="商品订单列表" class="subMenu" _href="/Order/productOrder/productOrderList.html" >商品订单</a>' +
                    '<a href="javascript:;" nav-id="71" nav-title="订单统计" class="subMenu" _href="/statistics/order/order-chart.html" >订单统计</a>' +
                    '<a href="javascript:;" nav-id="51" nav-title="优惠券列表" class="subMenu" _href="/coupon/couponManage/couponList/coupon-list.html" >优惠券列表</a>' +
                    '<a href="javascript:;" nav-id="56" nav-title="轮播图列表" class="subMenu" _href="/banner/bannerManage/bannerList/banner-list.html" style="margin-left:28px" >轮播图列表</a>'
                )
                //$('#messageAlertCount').text(getToAuditCount(3,1) + getReturnApplicationOrderCount(2,3) + getReturnApplicationOrderCount(3,3) + getReturnApplicationOrderCount(4,3) + getReturnApplicationOrderCount(5,3));
            }else if(depts[0].id == 4){
                $('.menu').append(
                    '<a href="javascript:;" nav-id="74" nav-title="用户列表" class="subMenu" _href="/user/leadingUser/leadingUserList/user-list.html" >用户列表</a>' +
                    '<a href="javascript:;" nav-id="75" nav-title="进思用户列表" class="subMenu" _href="/user/leadingUser/jinsiUserList/jinsi-user-list.html" >进思用户列表</a>' +
                    '<a href="javascript:;" nav-id="76" nav-title="非进思用户列表" class="subMenu" _href="/user/leadingUser/unJinsiUserList/un-jinsi-user-list.html" style="margin-left: 23px">非进思用户列表</a>' +
                    '<a href="javascript:;" nav-id="96" nav-title="反馈列表" class="subMenu" _href="/feedback/feedbackList/feedback-list.html" >反馈列表</a>' +
                    '<a href="javascript:;" nav-id="69" nav-title="人员统计" class="subMenu" _href="/statistics/personnel/personnel-chart.html" >人员统计</a>'
                )
            }
        }/*else if(depts.length == 3){
            $('.menu').append(
                '<a href="javascript:;" nav-id="9" nav-title="商品列表" class="subMenu" _href="/product/productManage/productList/product-list.html" >商品列表</a>' +
                '<a href="javascript:;" nav-id="16" nav-title="课程列表" class="subMenu" _href="/course/courseManage/courseList/course-list.html" >课程列表</a>' +
                '<a href="javascript:;" nav-id="23" nav-title="微圈列表" class="subMenu" _href="/microcircle/list/microcircle-list.html" >微圈列表</a>' +
                '<a href="javascript:;" nav-id="34" nav-title="商品审核列表" class="subMenu" _href="/examine/product/product-examine.html" >商品审核</a>' +
                '<a href="javascript:;" nav-id="36" nav-title="课程审核列表" class="subMenu" _href="/examine/course/course-examine.html" >课程审核</a>' +
                '<a href="javascript:;" nav-id="38" nav-title="微圈审核列表" class="subMenu" _href="/examine/microCircle/microCircle-examine.html" >微圈审核</a>' +
                '<a href="javascript:;" nav-id="9" nav-title="商品列表" class="subMenu" _href="/product/productManage/productList/product-list.html">商品列表</a>' +
                '<a href="javascript:;" nav-id="51" nav-title="优惠券列表" class="subMenu" _href="/coupon/couponManage/couponList/coupon-list.html" >优惠券列表</a>' +
                '<a href="javascript:;" nav-id="96" nav-title="反馈列表" class="subMenu" _href="/feedback/feedbackList/feedback-list.html" style="margin-left: 29px" >反馈列表</a>'
            )
        }else if(depts.length == 2){
            if(depts[0].id == 2 && depts[1].id == 3){
                $('.menu').append(
                    '<a href="javascript:;" nav-id="9" nav-title="商品列表" class="subMenu" _href="/product/productManage/productList/product-list.html" >商品列表</a>' +
                    '<a href="javascript:;" nav-id="16" nav-title="课程列表" class="subMenu" _href="/course/courseManage/courseList/course-list.html" >课程列表</a>' +
                    '<a href="javascript:;" nav-id="23" nav-title="微圈列表" class="subMenu" _href="/microcircle/list/microcircle-list.html" >微圈列表</a>' +
                    '<a href="javascript:;" nav-id="34" nav-title="商品审核列表" class="subMenu" _href="/examine/product/product-examine.html" >商品审核</a>' +
                    '<a href="javascript:;" nav-id="36" nav-title="课程审核列表" class="subMenu" _href="/examine/course/course-examine.html" >课程审核</a>' +
                    '<a href="javascript:;" nav-id="38" nav-title="微圈审核列表" class="subMenu" _href="/examine/microCircle/microCircle-examine.html" >微圈审核</a>' +
                    '<a href="javascript:;" nav-id="30" nav-title="课程评论" class="subMenu" _href="/comment/courseComment/course-comment-list.html" >课程评论</a>' +
                    '<a href="javascript:;" nav-id="31" nav-title="微圈评论" class="subMenu" _href="/comment/courseComment/course-comment-list.html" >微圈评论</a>' +
                    '<a href="javascript:;" nav-id="51" nav-title="优惠券列表" class="subMenu" _href="/coupon/couponManage/couponList/coupon-list.html" >优惠券列表</a>'
                )
            }else if(depts[0].id == 3 && depts[1].id == 4){
                $('.menu').append(
                    '<a href="javascript:;" nav-id="43" nav-title="课程订单列表" class="subMenu" _href="/Order/courseOrder/courseOrderList.html" >课程订单</a>' +
                    '<a href="javascript:;" nav-id="45" nav-title="商品订单列表" class="subMenu" _href="/Order/productOrder/productOrderList.html" >商品订单</a>' +
                    '<a href="javascript:;" nav-id="51" nav-title="优惠券列表" class="subMenu" _href="/coupon/couponManage/couponList/coupon-list.html" >优惠券列表</a>' +
                    '<a href="javascript:;" nav-id="56" nav-title="轮播图列表" class="subMenu" _href="/banner/bannerManage/bannerList/banner-list.html"  >轮播图列表</a>' +
                    '<a href="javascript:;" nav-id="74" nav-title="用户列表" class="subMenu" _href="/user/leadingUser/leadingUserList/user-list.html" style="margin-left: 27px" >用户列表</a>' +
                    '<a href="javascript:;" nav-id="96" nav-title="反馈列表" class="subMenu" _href="/feedback/feedbackList/feedback-list.html" style="margin-left: 43px" >反馈列表</a>' +
                    '<a href="javascript:;" nav-id="71" nav-title="订单统计" class="subMenu" _href="/statistics/order/order-chart.html" >订单统计</a>' +
                    '<a href="javascript:;" nav-id="69" nav-title="人员统计" class="subMenu" _href="/statistics/personnel/personnel-chart.html" >人员统计</a>'
                )
            }else if(depts[0].id == 2 && depts[1].id == 4){
                $('.menu').append(
                    '<a href="javascript:;" nav-id="16" nav-title="课程列表" class="subMenu" _href="/course/courseManage/courseList/course-list.html" >课程列表</a>' +
                    '<a href="javascript:;" nav-id="36" nav-title="课程审核列表" class="subMenu" _href="/examine/course/course-examine.html" >课程审核</a>' +
                    '<a href="javascript:;" nav-id="23" nav-title="微圈列表" class="subMenu" _href="/microcircle/list/microcircle-list.html" >微圈列表</a>' +
                    '<a href="javascript:;" nav-id="38" nav-title="微圈审核列表" class="subMenu" _href="/examine/microCircle/microCircle-examine.html" >微圈审核</a>' +
                    '<a href="javascript:;" nav-id="30" nav-title="课程评论" class="subMenu" _href="/comment/courseComment/course-comment-list.html" >课程评论</a>' +
                    '<a href="javascript:;" nav-id="31" nav-title="微圈评论" class="subMenu" _href="/comment/courseComment/course-comment-list.html" >微圈评论</a>' +
                    '<a href="javascript:;" nav-id="74" nav-title="用户列表" class="subMenu" _href="/user/leadingUser/leadingUserList/user-list.html">用户列表</a>' +
                    '<a href="javascript:;" nav-id="96" nav-title="反馈列表" class="subMenu" _href="/feedback/feedbackList/feedback-list.html">反馈列表</a>' +
                    '<a href="javascript:;" nav-id="69" nav-title="人员统计" class="subMenu" _href="/statistics/personnel/personnel-chart.html" >人员统计</a>'
                )
            }
        }*/
    }
    //查询待审核的课程、订单、微圈数量
    function getToAuditCount(type,result) {
        var toAuditCount;
        $.ajax({
            url: '/courseRecord/getToAuditCount',
            data: {
                type: type,
                result: result
            },
            async: false,
            dataType: 'json',
            success: function (data) {
                if(data.data != 0){
                    if(type == 2 && result == 2){
                        $('.footAlert').append(
                            '<a href="javascript:;" nav-id="36" nav-title="课程审核列表" class="subMenu" _href="/examine/course/course-examine.html" >待审核课程(<span class="messageAlertCount">'+data.data+'</span>)</a>'
                        )
                    }else if(type == 2 && result == 1){
                        $('.footAlert').append(
                            '<a href="javascript:;" nav-id="36" nav-title="课程审核列表" class="subMenu" _href="/examine/course/course-examine.html" >已通过审核的课程(<span class="messageAlertCount">'+data.data+'</span>)</a>'
                        )
                    }else if(type == 3 && result == 1){
                        $('.footAlert').append(
                            '<a href="javascript:;" nav-id="34" nav-title="商品审核列表" class="subMenu" _href="/examine/product/product-examine.html" >已通过审核的商品(<span class="messageAlertCount">'+data.data+'</span>)</a>'
                        )
                    }else if(type == 3 && result == 2){
                        $('.footAlert').append(
                            '<a href="javascript:;" nav-id="34" nav-title="商品审核列表" class="subMenu" _href="/examine/product/product-examine.html" >待审核商品(<span class="messageAlertCount">'+data.data+'</span>)</a>'
                        )
                    }else if(type == 4 && result == 2){
                        $('.footAlert').append(
                            '<a href="javascript:;" nav-id="38" nav-title="微圈审核列表" class="subMenu" _href="/examine/microCircle/microCircle-examine.html" >待审核微圈(<span class="messageAlertCount">'+data.data+'</span>)</a>'
                        )
                    }
                }
                toAuditCount = data.data;
            }
        });
        return toAuditCount;
    }
    function getReturnApplicationOrderCount(orderStatus,orderType) {
        var returnApplicationOrderCount;
        $.ajax({
            url: '/Order/getReturnApplicationOrderCount',
            data: {
                orderStatus: orderStatus,
                orderType: orderType
            },
            async: false,
            dataType: 'json',
            success: function (data) {
                if(data.data != 0){
                    if(orderType == undefined){
                        $('.footAlert').append(
                            '<a href="javascript:;" nav-id="47" nav-title="申请退订列表" class="subMenu" _href="/Order/unsubscribeOrder/applyUnsubscribeList.html" >申请退订订单(<span class="messageAlertCount">'+data.data+'</span>)</a>'
                        )
                    }else if(orderType == 2 && orderStatus == 2){
                        $('.footAlert').append(
                            '<a href="javascript:;" nav-id="43" nav-title="课程订单列表" class="subMenu" _href="/Order/courseOrder/courseOrderList.html" >待付款课程订单(<span class="messageAlertCount">'+data.data+'</span>)</a>'
                        )
                    }else if(orderType == 2 && orderStatus == 3){
                        $('.footAlert').append(
                            '<a href="javascript:;" nav-id="43" nav-title="课程订单列表" class="subMenu" _href="/Order/courseOrder/courseOrderList.html" >已付款课程订单(<span class="messageAlertCount">'+data.data+'</span>)</a>'
                        )
                    }else if(orderType == 3 && orderStatus == 2){
                        $('.footAlert').append(
                            '<a href="javascript:;" nav-id="45" nav-title="商品订单列表" class="subMenu" _href="/Order/productOrder/productOrderList.html" >待付款商品订单(<span class="messageAlertCount">'+data.data+'</span>)</a>'
                        )
                    }else if(orderType == 3 && orderStatus == 3){
                        $('.footAlert').append(
                            '<a href="javascript:;" nav-id="45" nav-title="商品订单列表" class="subMenu" _href="/Order/productOrder/productOrderList.html" >已付款商品订单(<span class="messageAlertCount">'+data.data+'</span>)</a>'
                        )
                    }else if(orderType == 3 && orderStatus == 4){
                        $('.footAlert').append(
                            '<a href="javascript:;" nav-id="45" nav-title="商品订单列表" class="subMenu" _href="/Order/productOrder/productOrderList.html" >待发货商品订单(<span class="messageAlertCount">'+data.data+'</span>)</a>'
                        )
                    }else if(orderType == 3 && orderStatus == 5){
                        $('.footAlert').append(
                            '<a href="javascript:;" nav-id="45" nav-title="商品订单列表" class="subMenu" _href="/Order/productOrder/productOrderList.html" >已发货商品订单(<span class="messageAlertCount">'+data.data+'</span>)</a>'
                        )
                    }
                }
                returnApplicationOrderCount = data.data;
            }
        });
        return returnApplicationOrderCount;
    }
    function getApplyForApplyRecordCount() {
        var applyForApplyRecordCount;
        $.ajax({
            url: '/applyRecord/getApplyForApplyRecordCount',
            async: false,
            dataType: 'json',
            data: {result: 2},
            success: function (data) {
                if(data.data != 0){
                    $('.footAlert').append(
                        '<a href="javascript:;" nav-id="56" nav-title="创作者申请列表" class="subMenu" _href="/user/creatorManage/creatorApplication/creator-application-list.html"  >创作者申请列表(<span class="messageAlertCount">'+data.data+'</span>)</a>'
                    )
                }
                applyForApplyRecordCount = data.data;
            }
        });
        return applyForApplyRecordCount;
    }
    function getDueSoonBannersCount(){
        var dueSoonBannersCount;
        $.ajax({
            url: '/banner/getDueSoonBannersCount',
            async: false,
            dataType: 'json',
            success: function (data) {
                if(data.data != 0){
                    $('.footAlert').append(
                        '<a href="javascript:;" nav-id="56" nav-title="轮播图列表" class="subMenu" _href="/banner/bannerManage/bannerList/banner-list.html"  >广告位即将到期(<span class="messageAlertCount">'+data.data+'</span>)</a>'
                    )
                }
                dueSoonBannersCount = data.data;
            }
        });
        return dueSoonBannersCount;
    }
    function getNav() {
        $.ajax({
            url: '/jsMenu/getJsMenus',
            data: {'userId':d.data.userId},
            method:'post',
            dataType:'json',
            success:function (data) {
                let nav = data.data;
                siYunNavRender(nav);
            }
        });
    }

    element.on('tab(siYunTab)', function(data){
        deleteIndex = $(this).attr("lay-id");
    });
    //将数据渲染到导航栏中
    function siYunNavRender(nav) {
        let html = '';
        html += '<ul class="layui-nav layui-nav-tree"  lay-filter="nav-tree">';
        $.each(nav, function (i, item) {
            html = html + '<li class="layui-nav-item">';
            html += '<a href="javascript:;">' + item.menuName + '</a>';
            if (item.children.length > 0) {
                html += '<dl class="layui-nav-child">';
                $.each(item.children, function (j, children) {
                    html += '<dd>';
                    if (children.url != null && children.url != '' && children.url != 'null' && children.url != 'Null' && children.url != 'NULL') {
                        html += '<a href="javascript:;"  class="subMenu" _href="' + children.url + '" >' + children.menuName + '</a>';
                    } else {
                        html += '<a href="javascript:;">' + children.menuName + '</a>';
                    }
                    if (children.children.length > 0) {
                        html += '<dl class="layui-nav-child">';
                        $.each(children.children, function (k, childrenItem) {
                            html += '<dd>' +
                                '<a href="javascript:;" nav-id="' + $(this).attr("menuId") + '" class="subMenu" nav-title="'+childrenItem.menuName+'" _href="' + childrenItem.url + '">' + childrenItem.menuName + '</a>' +
                                '</dd>';
                        });
                        html += '</dl>';
                    }
                });
                html += '</dl>';
            }
            html += '</li>';
        });
        html += '</ul>';
        //将拼接完成的字符串进行添加
        $("#siyunNav").append(html);
        //重载导航栏
        element.init();
        //隐藏首页选项卡的关闭按钮
        $('.subMenu').each(function () {
            if ($(this).text() == '首页') {
                $('li[lay-id=0] ').children('i').each(function () {
                    if ($(this).hasClass('layui-icon-close')) {
                        $(this).hide();
                    }
                });
                //初始展示首页
                $(this).click();
                $('.layui-nav-tree').children().children().first().click();
                $('.layui-nav-tree').children().children('dl').children().children().first().click();
            }
        });

        //当点击有siteactive属性的标签时，即左侧菜单栏中内容 ，触发点击事件
        $('.subMenu').on("click", function () {
            var dataid = $(this);
            var name = dataid.attr('nav-title');
            var url = dataid.attr("_href");
            var tab_layid = dataid.attr("nav-id");



            //1、 判断tab-layid=layid的tab页是否打开
            if ($(".layui-tab-title li[lay-id]").length <= 0) { //1.1 初始状态：1个Tab页也没有打开
                tabAdd(name, url, tab_layid); //打开tab页
                tabChange(tab_layid)//转到该tab页
            } else { //1.2   判断该Tab页是否已打开
                var isData = false; //初始化一个标志，为false说明未打开该tab项 为true则说明已有
                $.each($(".layui-tab-title li[lay-id]"),function () {
                    //如果点击左侧菜单栏所传入的id 在右侧tab项中的lay-id属性可以找到，则说明该tab项已经打开
                    if ($(this).attr("lay-id") == tab_layid) {
                        isData = true;
                    }
                });
                if (isData == false) {
                    //标志为false 新增一个tab项
                    tabAdd(name, url, tab_layid); //1.2.1  该Tab页未打开，则打开该tab页
                }

                tabChange(tab_layid)//1.2.2 转到该tab页

            }
        });

        //右键关闭
        function siYunTabRightClick(id) {
            //隐藏浏览器右键弹框
            $('.layui-tab-title li').on('contextmenu', function () {
                return false;
            });
            $('.layui-tab-title,.layui-tab-title li').click(function () {
                $('.rightMenu').hide();
            });
            //桌面点击右击
            $('.layui-tab-title li').on('contextmenu', function (e) {
                var popupmenu = $(".rightMenu");
                popupmenu.find("li").attr("data-id", id); //在右键菜单中的标签绑定id属性

                //判断右侧菜单的位置
                l = ($(document).width() - e.clientX) < popupmenu.width() ? (e.clientX - popupmenu.width()) : e.clientX;
                t = ($(document).height() - e.clientY) < popupmenu.height() ? (e.clientY - popupmenu.height()) : e.clientY;
                popupmenu.css({left: l, top: t}).show(); //进行绝对定位
                //alert("右键菜单")
                return false;
            });
            $(".rightMenu li").click(function () {
                //右键点击关闭全部
                if ($(this).attr("data-type") == "closeAll") {
                    var tabTitle = $(".layui-tab-title li");
                    var ids = new Array();
                    $.each(tabTitle, function (i) {
                        ids[i] = $(this).attr("lay-id");
                    });
                    tabDeleteAll(ids);
                } else if ($(this).attr("data-type") == "closeOther") {
                    $.each($(".layui-tab-title li[lay-id]"), function () {
                        //如果点击左侧菜单栏所传入的id 在右侧tab项中的lay-id属性可以找到，则说明该tab项已经打开
                        if ($(this).attr("lay-id") != deleteIndex) {
                            tabDeleteOther($(this).attr("lay-id"));
                        }
                    });
                }
                $('.rightMenu').hide();
            });

        }
        $('#closeThis').click(function () {
            $.each($(".layui-tab-title li"), function (i,item) {
                if($(item).attr('class') == 'layui-this'){
                    var layid = $(this).attr("lay-id");
                    if(layid != 0){
                        tabDelete(layid)
                    }
                }
            });
        });
        //关闭全部
        function tabDeleteAll(ids) {
            $.each(ids, function (i, item) {
                if (item != 0) {
                    tabDelete(item);
                }
            });
        }
        //关闭其它
        function tabDeleteOther(id) {
            if (id != 0) {
                tabDelete(id)
            }
        }
        tabAdd = function tabAdd(name, url, layid) {
            if(name == '首页'){
                tabChange(0);
                return;
            }
            var tabId = localStorage.getItem('tabId');
            element.tabAdd('siYunTab', {
                title: name //'选项卡的标题'
                , content: '<iframe before-lay-id="'+tabId+'" style="height: 100%" frameborder="0" src="' + url + '" class="iframe" iframeId="'+layid+'"></iframe>'
                , id: layid//'选项卡标题的lay-id属性值'
            });
            siYunTabRightClick(layid);   //给tab绑定右击事件
            localStorage.setItem('tabId',layid)
        }
        tabChange = function tabChange(layid) {
            element.tabChange('siYunTab', layid);

        }


        tabDelete = function tabDelete(id){
            element.tabDelete('siYunTab', id);
        }
        tabParentChange = function tabParentChange(beforeTabId){
            $.each($('.subMenu'),function (i, item) {
                if($(item).attr('nav-id') == beforeTabId){
                    $(this).click();
                }
            });
        }
        //添加选项卡
        addTab = function addTab(tabId) {
            $.each($('.subMenu'),function (i, item) {
                if($(item).attr('nav-id') == tabId){
                    $(this).click();
                }
            })
        }
    }
    //获取 年月日 时分秒 星期
    function setTime(){
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var today = date.getDate();
        var hour = date.getHours();
        var minute = date.getMinutes();
        var second = date.getSeconds();
        //当小时小于10时进行补零
        return zeroFill(year) + '-' + zeroFill(month) + '-' + zeroFill(today) +  ' ' + zeroFill(hour) + ':' + zeroFill(minute) + ':' + zeroFill(second);
    }
    //补零
    function zeroFill(time){
        if(time < 10){
            time = '0' + time;
        }
        return time;
    }
    //获取当前登录用户的权限
    var user =localStorage.getItem("user");
    user = JSON.parse(user);
    $.ajax({
        url:"/HomePage/getUserGrade",
        data:{"userId":user.data.userId},
        type:"post",
        dataType:"json",
        success:function (data) {
                if (data.data == 1){
                    $("#iframe").attr("src","/index/systemHome/homePage/homePage.html");
                }else if(data.data == 2){
                    $("#iframe").attr("src","/index/systemHome/homePage/index-welcome-teacher.html");
                }else if(data.data == 3){
                    $("#iframe").attr("src","/index/systemHome/homePage/index-welcome-operate.html");
                }else if(data.data == 4){
                    $("#iframe").attr("src","/index/systemHome/homePage/index-welcome-personnelMatters.html");
                }else if(data.data == 5){
                    $("#iframe").attr("src","/index/systemHome/homePage/index-welcome-TeacherOperation.html");
                }else if(data.data == 6){
                    $("#iframe").attr("src","/index/systemHome/homePage/index-welcome-OperationPersonnel.html");
                }else if(data.data == 7){
                    $("#iframe").attr("src","/index/systemHome/homePage/index-welcome-PersonnelTeacher.html");
                }else if(data.data == 8){
                    $("#iframe").attr("src","/index/systemHome/homePage/index-welcome-TeacherOperationPersonnel.html");
                }

        }
    })
});